define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'staff/achievements/index' + location.search,
                    add_url: 'staff/achievements/add',
                    edit_url: 'staff/achievements/edit',
                    del_url: 'staff/achievements/del',
                    multi_url: 'staff/achievements/multi',
                    import_url: 'staff/achievements/import',
                    table: 'staff_achievements',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'staff_id', title: __('Staff_id')},
                        // {field: 'shop_id', title: __('Shop_id')},
                        {field: 'achievements_time', title: __('Achievements_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'jan', title: __('Jan'), operate:'BETWEEN'},
                        {field: 'feb', title: __('Feb'), operate:'BETWEEN'},
                        {field: 'mar', title: __('Mar'), operate:'BETWEEN'},
                        {field: 'apr', title: __('Apr'), operate:'BETWEEN'},
                        {field: 'may', title: __('May'), operate:'BETWEEN'},
                        {field: 'jun', title: __('Jun'), operate:'BETWEEN'},
                        {field: 'jul', title: __('Jul'), operate:'BETWEEN'},
                        {field: 'aug', title: __('Aug'), operate:'BETWEEN'},
                        {field: 'sep', title: __('Sep'), operate:'BETWEEN'},
                        {field: 'oct', title: __('Oct'), operate:'BETWEEN'},
                        {field: 'nov', title: __('Nov'), operate:'BETWEEN'},
                        {field: 'dec', title: __('Dec'), operate:'BETWEEN'},
                        {field: 'first_quarter', title: __('First_quarter'), operate:'BETWEEN'},
                        {field: 'second_quarter', title: __('Second_quarter'), operate:'BETWEEN'},
                        {field: 'third_quarter', title: __('Third_quarter'), operate:'BETWEEN'},
                        {field: 'fourth_quarter', title: __('Fourth_quarter'), operate:'BETWEEN'},
                        {field: 'annual', title: __('Annual'), operate:'BETWEEN'},
                        {field: 'staff.name', title: __('Staff.name'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $(".month_check").css("background-color", "red");
            $(".month").show();
            $(".quarter").hide();
            $(".year").hide();
            $(document).on("click", ".month_check", function () {
                $(this).css("background-color", "red");
                $(".quarter_check").css("background-color", "#444c69");
                $(".year_check").css("background-color", "#444c69");
                $(".month").show();
                $(".quarter").hide();
                $(".year").hide();
                $("#c-qnums").val("");
                $("#c-achievementsq_time").val("");
                $("#c-quarter").val("");
                $("#c-yearnums").val("");
                $("#c-year_achievements_time").val("");
            });
            $(document).on("click", ".quarter_check", function () {
                $(this).css("background-color", "red");
                $(".month_check").css("background-color", "#444c69");
                $(".year_check").css("background-color", "#444c69");
                $(".month").hide();
                $(".quarter").show();
                $(".year").hide();
                $("#c-nums").val("");
                $("#c-achievements_time").val("");
                $("#c-yearnums").val("");
                $("#c-year_achievements_time").val("");
            });
            $(document).on("click", ".year_check", function () {
                $(this).css("background-color", "red");
                $(".quarter_check").css("background-color", "#444c69");
                $(".month_check").css("background-color", "#444c69");
                $(".month").hide();
                $(".quarter").hide();
                $(".year").show();
                $("#c-qnums").val("");
                $("#c-achievementsq_time").val("");
                $("#c-quarter").val("");
                $("#c-nums").val("");
                $("#c-achievements_time").val("");
            });
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
